import { CrudOptions } from "@nestjsx/crud";
import { HandleStatus } from "libs/db/entity/enum/handle-status.enum";
import { Village } from "libs/db/entity/village.entity";
import { LoggerInfo, moduleLoggerInfo } from "../_decorator/logger-info";

export const VillageCrudOps: CrudOptions = {
  model: {
    type: Village
  },
  query: {
     
    join: {
      town: {
        exclude:  ["updatedAt", "deleteAt"],
      },
      "town.area": {
        exclude:  ["updatedAt", "deleteAt"],
      },
      group: {
        exclude:  ["updatedAt", "deleteAt"],
      },
      villager: {
        exclude:  ["updatedAt", "deleteAt"],
      },
      subsidyType: {
        exclude:  ["updatedAt", "deleteAt"],
      },
      subsidy: {
        exclude:  ["updatedAt", "deleteAt"],
      },
      "subsidyType.subsidy": {
        exclude:  ["updatedAt", "deleteAt"],
      },  
      orgActionType: {
        exclude:  ["updatedAt", "deleteAt"],
      },
      villageAction: {
        exclude:  ["updatedAt", "deleteAt"],
      },
      villageActionType: {
        exclude:  ["updatedAt", "deleteAt"],
      },
      resourcesType: {
        exclude:  ["updatedAt", "deleteAt"],
      },
      assetsType: {
        exclude:  ["updatedAt", "deleteAt"],
      },
      // createdAt: {
      //   alias: "created"
      // },
    },
    exclude: ["updatedAt", "deleteAt"]
  },
  routes: {
    getManyBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('行政村信息查询', HandleStatus.LOG)
        ),
      ],
    },
    getOneBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('单个行政村信息查询', HandleStatus.LOG)
        ),
      ],
    },
    createOneBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('新增行政村信息', HandleStatus.INFO)
        ),
      ],
      returnShallow: true,
    },
    createManyBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('行政村信息上传', HandleStatus.DATA)
        ),
      ],
    },
    replaceOneBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('修改行政村信息', HandleStatus.WARN)
        ),
      ],
      allowParamsOverride: true,
      returnShallow: true,
    },
    updateOneBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('修改行政村信息', HandleStatus.WARN)
        ),
      ],
      allowParamsOverride: true,
      returnShallow: true,
    },
    deleteOneBase: {
      interceptors: [],
      decorators: [
        LoggerInfo(
          new moduleLoggerInfo ('删除行政村信息', HandleStatus.ERROR)
        ),
      ],
      returnDeleted: true,
    },
  },
  dto: {
    create: Village,
    replace: Village
  },
  serialize: {
    getMany: Village,
    get: Village,
    create: Village,
    createMany: Village,
    update: Village,
    replace: Village,
    delete: Village,
  }
}